package math;

/**
 * Created by fengliejv on 2017/11/30.
 */
public class BulbSwitcher319 {

    //模拟，超时
    public int bulbSwitch(int n) {
        boolean[] lamp = new boolean[n+1];
        for (int i = 0; i < lamp.length; i++) {
            lamp[i] = false;
        }
        int i = 1;
        while (i<=lamp.length){
            for (int j = i; j < lamp.length; j=j+i) {
                lamp[j]=!lamp[j];
            }
            i++;
        }
        int result = 0;
        for (int j = 0; j < lamp.length; j++) {
            if(lamp[j]){
                result++;
            }
        }
        return result;
    }

//    public int bulbSwitch(int n) {
//
//        return (int)Math.sqrt(n);
//
//    }
}
